// JavaScript Document
//var jsonserver = "http://192.168.6.52:8090";
var autologin = false;
/**********************************************改变单选框的状态***************************************************/
 function chageStatus(a){
	    if($("#check_"+a).attr("checked")=="checked"){
			$("#div_"+a).attr("class","uncheck");
			$("#check_"+a).removeAttr("checked");
		}else{
			$("#div_"+a).attr("class","check");
			$("#check_"+a).attr("checked","checked");
		}
	}
	
/**-----------------------------------------------------隐藏地址栏-----------------------------------------------------------*/
window.onload=function(){ 
if(document.documentElement.scrollHeight <= document.documentElement.clientHeight) { 
bodyTag = document.getElementsByTagName('body')[0]; 
bodyTag.style.height = document.documentElement.clientWidth / screen.width * screen.height + 'px'; 
} 
setTimeout(function() { 
window.scrollTo(0, 1) 
}, 0); 
}; 
/***--------------------------------------------------------------------------------------------------------------------------*/
function wait_me(){
	  $("#message").css("display","none");
}
/**------------------------------------------------------验证---------------------------------------------------------------------*/
  var wrongTypePhone;
  var wrongTypePwd;
  var wrongPhoneHtml = new Array("","请输入手机号","手机号的长度必须是11位","请输入正确的手机号","您的用户名或密码错误","超时,请重新登陆");
  var wrongPwdHtml = new Array("","请输入验证码","验证码长度必须是6位");
  var pwdFlag = false;
 //失去焦点后验证格式是否正确
 function validate(obj){
	 var objid = $(obj).attr("id");
	 if(objid=="phoneNum"){
	 wrongTypePhone = 0;
	 var phoneNum = $("#phoneNum").val();
	 phoneLength=phoneNum.length; 
	 if(phoneLength==0)
	    wrongTypePhone =1;
	 else if(phoneLength!=11){
		 wrongTypePhone =2;
	 }
	 else{
		 var phoneParth = /^1[3,5,8]\d{9}$/;
		 if( phoneLength!=11 || !phoneParth.exec(phoneNum)){
			 wrongTypePhone = 2;
		 }else{
			wrongTypePhone=0;
		 }
	 }
		$("#msg1").html(wrongPhoneHtml[wrongTypePhone]);
		if(wrongTypePhone==0){
			return true;
		}else{
			return false;
		}
	 }else{
	 wrongTypePwd = 0;
	 var yanzhengma = $("#yanzhengma").val();
	 yzmLength=yanzhengma.length;
	
	if(yanzhengma==0)
	   wrongTypePwd = 1;
	 else{
		 if(yzmLength!=6)
		    wrongTypePwd=2;
		 }
	$("#msg2").html(wrongPwdHtml[wrongTypePwd]);
	if(wrongTypePhone==0){
			return true;
		}else{
			return false;
		}
	 }
	 }
/**------------------------------------------------------发送验证码----------------------------------------------------------------------*/
function function_yanzhengma(){
 if(validate($("#phoneNum"))){
	  $.natureajax({
	   url:jsonserver+"login_SendSms.do?callback=?",
	   data:{"phonenum":$("#phoneNum").val()},
	   type:"POST",
	   dataType:"jsonp",
	   success: function(data){
		   if(data[0].result=='1'){
			  jAlert('验证码已发送,请查收!','系统提示');
			   //jAlert(data[0].info,'系统提示');
		   }
		   else if(data[0].result=='2'){
			   //把老用户的信息保存到cookie
			   $.cookie("laoyonghu",data[0].result,{path:"/",expires:15});
			   jAlert("您是老用户，请直接用密码登陆!",'系统提示');
			   $("#message").css("display","block");
		   }
		   else if(data[0].result=='0'){ 
			   jAlert("请求失败,请重新输入您的手机号!",'系统提示');
			   jAlert(data[0].info,'系统提示');
		   }
		  },error:function(data){  
		   jAlert("服务器忙,请稍后再试。。",'系统提示');
	  } 	
	});
 }else{	
		jAlert("手机号为空或输入不正确!",'系统提示');
	}
	
}
/***----------------------------------------------------记住密码自动登陆--------------------------------------------------------------**/
 //当页面加载
	 $(document).ready(function(e) {
		 versionFlag=="jx"?$(".img_center").attr("class","img_center1"):null;
        if($.cookie("phoneNum")!=null&&$.cookie("yanzhengma")!=null){
		//给文本框赋值
	    $("#phoneNum").attr("value",$.cookie('phoneNum'));
	    $("#yanzhengma").attr("value",$.cookie('yanzhengma'));
		//If记住密码勾选了
		if($.cookie("is_jizhumima")=='1'){
			//给自动登陆和设置为选中状
		   $("#check_jzmm").attr("checked","checked");
		   $("#div_jzmm").attr("class","check");      
		}
		if($.cookie("is_autologin")=='1'){
		   //给自动登陆和保存密码设置为选中状态
		  
	       $("#check_jzmm").attr("checked","checked");
		   $("#check_zddl").attr("checked","checked");
		   $("#div_jzmm").attr("class","check");
		   $("#div_zddl").attr("class","check");
		   //等待3秒自动登陆
		   autologin = true;
		   auto_login_bys3();
		}		
		}else{
			
		}
    });
    
	 //登陆
	 function function_load(){
		$("#btn_load").css("color","yellow");
		if(validate($("#phoneNum")) && validate($("#yanzhengma"))){
			  $.natureajax({
			  url:jsonserver+"login_valiCode.do?callback=?",
			  type:"GET",
			  data:{"phonenum":$("#phoneNum").val(),"vcode":$("#yanzhengma").val()},
			  dataType:"jsonp", 
			  success: function(data){
				   if(data[0].result=="1"){
					 $.cookie("user",'0',{path:"/",expires:15});
					 $.cookie("NP_INFO_TELNO",data[2].NP_INFO_TELNO,{path:"/",expires:15});
			         $.cookie("NP_INFO_ID",data[2].NP_INFO_ID,{path:"/",expires:15});
			         $.cookie("U_KEY",data[2].ukey);
			         $.cookie("IS_BJ_LT",data[2].IS_BJ_LT,{path:"/",expires:15});
					 $.cookie("LT_VIP",data[2].LT_VIP,{path:"/",expires:15});
					 $.cookie("newuser","isNull",{path:"/",expires:15});
					 $.cookie("phoneNum",data[2].NP_INFO_TELNO,{path:"/",expires:15});
					 window.location.href="index.html";
					 }else{
						 jAlert("用户名或者验证码错误！请重新输入。",'系统提示');
					 }
			
			 },error: function(){ 
				 jAlert("请求失败，请稍后再试。。",'系统提示');
				}
			 }); 
		 }else{ 
			 jAlert("用户名或者验证码为空或者输入有误，请重新输入!",'系统提示');
		  }
		  
		 }
		 
//记住密码是否选中
function writemimacookie(){
	if($("#check_jzmm").attr("checked")=="checked"){
			//保存   保存密    码选中
			 $.cookie("is_jizhumima","1",{path:"/",expires:15});
			 $.cookie("phoneNum",$("#phoneNum").val(),{path:"/",expires:15});
			 $.cookie("yanzhengma",$("#yanzhengma").val(),{path:"/",expires:15});
	}else{
		$.cookie("is_jizhumima","0",{path:"/",expires:15});
	 }
}

//自动登陆是否选中
function autologincheck(){
	if($("#check_zddl").attr("checked")=="checked"){
		//保存自动登陆选中状态
		$.cookie("is_autologin","1",{path:"/",expires:15});
		//保存记住密码选中状态
		$.cookie("is_jizhumima","1",{path:"/",expires:15});
		$("#check_jzmm").attr("class","check");
		$("#check_zddl").attr("class","check");
	}else{
		$.cookie("is_autologin","0",{path:"/",expires:15});
	}
	writemimacookie();
}

//等待3秒自动登陆
var t = 4;
function auto_login_bys3(){
t--;
if (t==0){
  if(autologin){
    function_load();
   }
}else{
	
}
setTimeout("auto_login_bys3();",1000);
}

//忘记密码
function forget_mima(){
  if($("#phoneNum").val()==null&&$("#phoneNum").val()==""){
	   jAlert("请输入手机号!",'系统提示');
  }
  else{
	$.natureajax({
	  url:jsonserver+"login_forgetPassword.do?callback=?",
	  data:{"NP_INFO_TELNO":$("#phoneNum").val()},
	  type:"POST",
	  dataType:"jsonp",
	  success:function(data){
		  if(data[0].result=='1'){
			 jAlert("您的密码已发送到"+data[1].email+"邮箱",'系统提示');
		  }else{ 
			 jAlert(data[0].info,'系统提示');
		  }
	  },error:function(){
		  jAlert("请求出错,请重新输入！",'系统提示');
	  }  
  });  
 }	
}



/**************************************************返回到登陆页面*********************************************************************/
function btn_back_click(){
  window.location.href="login.html";	
}	 



	 